package com.octopus.core.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 下载器工具类
 *
 * @author yang_shoulai@hoperun.com
 * @date 2019/08/03
 */
public class DownloaderUtils {
  private static final Pattern CHARSET = Pattern.compile(".*charset=([^;]*).*");

  /**
   * 从HTTP响应头Content-Type中提取编码
   *
   * @param contentType contentType
   * @return 编码
   */
  public static String getCharsetFromContentType(String contentType) {
    if (!StringUtils.isEmpty(contentType)) {
      Matcher matcher = CHARSET.matcher(contentType.toLowerCase());
      if (matcher.matches()) {
        return matcher.group(1);
      }
    }
    return null;
  }


}
